package com.typhoon.spring_boot_demo1.service.impl;

import com.typhoon.spring_boot_demo1.bean.Order;
import com.typhoon.spring_boot_demo1.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Order queryByOrderId(Long orderId) {
        List<Order> list = this.jdbcTemplate.query("select * from TOrder where orderId = ? limit 1",BeanPropertyRowMapper.newInstance(Order.class),orderId);
        if(null == list || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
}
